<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 16-11-27
 * Time: 上午12:30
 */
namespace app\wateradmin\model;

use app\common\model\BaseSeller;
use think\Db;
class ShopSeller extends BaseSeller {

    /**
     * 会员详细信息
     * @param array $condition
     * @param string $field
     * @return array
     */
    public function getSellerInfo($condition, $field ="*"){
        if(empty($condition)){
            return false;
        }
        return Db::name('shop_seller')->field($field)->where($condition)->find();
    }

    /**
     * 会员列表
     * @param array $condition
     * @param string $field
     * @param number $page
     * @param string $order
     */
    public function getSellerList($condition , $field='*' , $order=' addtime DESC ' , $pagesize=15){
        $condition = 'parent_id = '.session('shop').' and `status`=1';
        $query = array();
        if(isset($_GET['key'])&&!empty($_GET['key'])){
            $condition .= ' AND  ( seller_name like "%'.$_GET['key'].'%" OR seller_tel like "%'.$_GET['key'].'%" OR seller_truename like "%'.$_GET['key'].'%" )';
            $query = array('key'=>$_GET['key']);
        }
        if(isset($_GET['start_time'])&&!empty($_GET['start_time'])&&isset($_GET['end_time'])&&!empty($_GET['end_time'])){
            $start_time=strtotime($_GET['start_time']);
            $end_time=strtotime($_GET['end_time']);
            $condition .= ' AND (addtime >='.$start_time.' AND addtime <='.$end_time.')';
            $query = array(
                'start_time'=>$_GET['start_time'],
                'end_time'=>$_GET['end_time']
            );
        }
        $count = Db::name('shop_seller')->where($condition)->count();
        $list = Db::name('shop_seller')->field($field)->where($condition)->order($order)->paginate($pagesize,false,['query'=>$query]);
        return array('count'=>$count,'list'=>$list);
    }

}